<?php
include("../resources/database/database.php");

$custid  = "CUST-";
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= rand(0,9);
$custid .= "-OMER";

$salutation     = $_POST['salutation'];
$firstname      = $_POST['fname'];
$midname        = $_POST['mid'];
$lastname       = $_POST['lname'];
$gender         = $_POST['gender'];
$contact        = $_POST['contact'];
$email          = $_POST['email'];
$house          = $_POST['house'];
$street         = $_POST['street'];
$barangay       = $_POST['barangay'];
$town           = $_POST['town'];
$province       = $_POST['province'];
$event          = $_POST['event'];
$number         = $_POST['number'];
$date           = $_POST['year']."-".$_POST['month']."-".$_POST['day'];

$save_customer = "
                    INSERT INTO tbl_customer()
                    VALUES(
                        '{$custid}',
                        '{$salutation}',
                        '{$firstname}',
                        '{$midname}',
                        '{$lastname}',
                        '{$gender}',
                        '{$contact}',
                        '{$email}',
                        '{$house}',
                        '{$street}',
                        '{$barangay}',
                        '{$town}',
                        '{$province}'
                    )
                ";
                
$save_event = "
                    INSERT INTO tbl_event_reg(
                        CUST_ID,
                        EVENT_PERSON_NUMBER,
                        EVENT_TYPE,
                        EVENT_DATE
                    )
                    values(
                        '{$custid}',
                        '{$number}',
                        '{$event}',
                        '{$date}'
                    )
            ";
            
$sql = mysql_query($save_customer);
$sql2 = mysql_query($save_event);

if($sql && $sql2) :
?>
<div id="success">
    <label>Reservation of <?php echo $salutation." ".$firstname." ".$midname.". ".$lastname." "; ?>successfully saved!</label>
    <br>
    <a href="../">Make another reservation</a>
</div>
<?php else : ?>
<div id="Ooooooopsss!!!! Error!!!!!!!</label>
</div>
<?php endif; ?>

<style>
    
    #success {
	font-size:30px;
	font-weight:bold;
	text-align:center;
        font-family:calibri;
        border:1px solid #c0c0c0;
        background:#ddfed3;
        margin:10px;
        padding:20px;
        text-transform:capitalize;
        }
    #success a {
        font-size:18px;
        text-decoration:none;
        color:#318d0a;
    }
    #success a:hover {
        text-decoration:underline;
    }
    
</style>